<?php
namespace BP\Sys;

use BP\En\EntityNoName;

require_once("BP/En/Map.php");
class SysEnumMain extends EntityNoName {
	public function getCfgVal () 
	{
		return $this->GetValStrByKey(SysEnumMainAttr::$CfgVal);
	}
	public function setCfgVal ($value) // [String value]
	{
		$this->SetValByKey(SysEnumMainAttr::$CfgVal, $value);
	}
	public function getLang () 
	{
		return $this->GetValStrByKey(SysEnumMainAttr::$Lang);
	}
	public function setLang ($value) // [String value]
	{
		$this->SetValByKey(SysEnumMainAttr::$Lang, $value);
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String ($no) // [String no]
	{
		$me = new self();
		try 
		{
			$me->setNo($no);
			$me->Retrieve();
		}
		catch (\RuntimeException $ex)
		{
			$ses = SysEnums::constructor__String($no);
			if (($ses->size() == 0))
			{
				throw $ex;
			}
			$me->setNo($no);
			$me->setName("未命�?");
			$cfgVal = "";
			foreach ($ses->ToJavaList() as $item) 			{
				$cfgVal += ((("@" . $item->getIntKey()) . "=") . $item->getLab());
			}
			$me->setCfgVal($cfgVal);
			$me->Insert();
		}
		return $me;
	}
	protected function beforeDelete () 
	{
		$attrs = MapAttrs::constructor__();
		$qo = new QueryObject($attrs);
		$qo->AddWhere(MapAttrAttr::$UIBindKey, $this->getNo());
		$i = $qo->DoQuery();
		if (($i == 0))
		{
			$ses = SysEnums::constructor__();
			$ses->Delete(SysEnumAttr->EnumKey, $this->getNo());
		}
		else
		{
			$msg = "错误:下列数据已经引用了枚举您不能删除它�??";
			foreach ($attrs->ToJavaList() as $attr) 			{
				$msg += (((("\t\n" . $attr->getField()) . $attr->getName()) . " Table = ") . $attr->getFK_MapData());
			}
			throw new \RuntimeException($msg);
		}
		return parent->beforeDelete();
	}
	abstract function afterInsert (); 
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		$map = new Map("Sys_EnumMain", "枚举");
		$map->Java_SetDepositaryOfEntity($Depositary->None);
		$map->Java_SetDepositaryOfMap($Depositary->Application);
		$map->Java_SetEnType($EnType->Sys);
		$map->AddTBStringPK(SysEnumMainAttr::$No, NULL, "编号",  TRUE ,  FALSE , 1, 40, 8);
		$map->AddTBString(SysEnumMainAttr::$Name, NULL, "名称",  TRUE ,  FALSE , 0, 40, 8);
		$map->AddTBString(SysEnumMainAttr::$CfgVal, NULL, "配置信息",  TRUE ,  FALSE , 0, 1500, 8);
		$map->AddTBString(SysEnumMainAttr::$Lang, "CH", "语言",  TRUE ,  FALSE , 0, 10, 8);
		$this->set_enMap($map);
		return $this->get_enMap();
	}
}
?>
